package main

import "fmt"

type orderInfo struct {
	orderId int
}

//模拟订单(生产消费者模型)
func main() {
	ch := make(chan *orderInfo)
	go producter(ch)
	consumer(ch)
}

func producter(out chan<- *orderInfo) { //生产者：生成订单
	for i := 1; i < 11; i++ { //循环生成10份订单
		oi := &orderInfo{i}
		out <- oi //写入channel
	}

	close(out) //写完，关闭channel
}

func consumer(in <-chan *orderInfo) { //消费者：消费订单
	for oi := range in {
		fmt.Printf("读到的orderId为：%d\n", oi.orderId) //模拟处理订单
	}
}
